package com.ruoyi.web.controller.productionre;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.production.domain.SimpleProduction;
import com.ruoyi.production.domain.StromaReturn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.RegulatorReturn;
import com.ruoyi.production.service.IRegulatorReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调节剂退回Controller
 *
 * @author ruoyi
 * @date 2021-07-19
 */
@Api("调节剂退回")
@RestController
@RequestMapping("/production/regulatorre")
public class RegulatorReturnController extends BaseController
{
    @Autowired
    private IRegulatorReturnService regulatorReturnService;

    /**
     * 查询调节剂退回列表
     */
    @ApiOperation("查询调节剂退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:list')")
    @GetMapping("/list")
    public TableDataInfo list(RegulatorReturn regulatorReturn)
    {
        startPage();
        List<RegulatorReturn> list = regulatorReturnService.selectRegulatorReturnList(regulatorReturn);
        return getDataTable(list);
    }

    /**
     * 导出调节剂退回列表
     */
    @ApiOperation("导出调节剂退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:export')")
    @Log(title = "调节剂退回", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RegulatorReturn regulatorReturn)
    {
        List<RegulatorReturn> list=new ArrayList();
        //通过id来取
        Long a[]=regulatorReturn.getRegulagorReturnIds();
        for(int i=0;i<a.length;i++) {
            RegulatorReturn list1 = regulatorReturnService.selectRegulatorReturnById(a[i]);
            list.add(list1);
        }

        ExcelUtil<RegulatorReturn> util = new ExcelUtil<RegulatorReturn>(RegulatorReturn.class);
        return util.exportExcel(list, "调节剂退回数据");
    }

    /**
     * 获取调节剂退回详细信息
     */
    @ApiOperation("获取调节剂退回详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:query')")
    @GetMapping(value = "/{regulagorReturnId}")
    public AjaxResult getInfo(@PathVariable("regulagorReturnId") Long regulagorReturnId)
    {
        return AjaxResult.success(regulatorReturnService.selectRegulatorReturnById(regulagorReturnId));
    }

    /**
     * 新增调节剂退回
     */
    @ApiOperation("新增调节剂退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:add')")
    @Log(title = "调节剂退回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RegulatorReturn regulatorReturn)
    {
        return toAjax(regulatorReturnService.insertRegulatorReturn(regulatorReturn));
    }

    /**
     * 修改调节剂退回
     */
    @ApiOperation("修改调节剂退回")
    @ResponseBody
    @PreAuthorize("@ss.hasAnyPermi('production:regulatorre:edit,production:regulatorre:permit')")
    @Log(title = "调节剂退回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RegulatorReturn regulatorReturn)
    {
        return toAjax(regulatorReturnService.updateRegulatorReturn(regulatorReturn));
    }

    /**
     * 删除调节剂退回
     */
    @ApiOperation("删除调节剂退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:remove')")
    @Log(title = "调节剂退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regulagorReturnIds}")
    public AjaxResult remove(@PathVariable Long[] regulagorReturnIds)
    {
        return toAjax(regulatorReturnService.deleteRegulatorReturnByIds(regulagorReturnIds));
    }

    /**
     * 获取调节剂类型下拉框
     */
    @ApiOperation("获取调节剂类型下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:type')")
    @GetMapping("/type")
    public TableDataInfo getRegulatorType(){

        List<RegulatorReturn> list = regulatorReturnService.getRegulatorType();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (RegulatorReturn regulatorReturn:list) {
            Long id = regulatorReturn.getRegulatorTypeId();
            String name = regulatorReturn.getRegulatorType();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取调节剂名称下拉框
     */
    @ApiOperation("获取调节剂名称下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:name')")
    @GetMapping("/name")
    public TableDataInfo getRegulatorName(){

        List<RegulatorReturn> list = regulatorReturnService.getRegulatorName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (RegulatorReturn regulatorReturn:list) {
            Long id = regulatorReturn.getRegulatorNameId();
            String name = regulatorReturn.getRegulatorName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<RegulatorReturn> list = regulatorReturnService.getUserName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (RegulatorReturn regulatorReturn:list) {
            Long id = regulatorReturn.getUserId();
            String name = regulatorReturn.getUserName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取有效含量下拉框
     */
    @ApiOperation("获取有效含量下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:content')")
    @GetMapping("/content/{regulatorNameId}")
    public TableDataInfo getContent(@PathVariable("regulatorNameId") Long regulatorNameId){

        List<String> list = regulatorReturnService.getContent(regulatorNameId);
        return getDataTable(list);
    }

    /**
     * 获取公司列表下拉框
     */
    @ApiOperation("获取公司列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:regulatorre:origincompany')")
    @GetMapping("/origincompany/{regulatorNameId}")
    public TableDataInfo getOriginCompany(@PathVariable("regulatorNameId") Long regulatorNameId){

        List<String> list = regulatorReturnService.getOriginCompany(regulatorNameId);
        return getDataTable(list);
    }
}
